package com.j.lemon.learn.basic.object.justtest;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author lijunjun
 * @Date 2019-02-21 13:56
 * @Description
 */
public class ProxyTest implements InvocationHandler {
    private Object target;

    public ProxyTest(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println(method.getName());
        System.out.println(" this is log");
        method.invoke(target,args);
        return null;
    }
}

class Test{
    public static void main(String[] args) {
        Employee employee = new Employee(19,"zhangsan");
        Human o = (Human) Proxy.newProxyInstance(employee.getClass().getClassLoader(), employee.getClass().getInterfaces(), new ProxyTest(employee));
        o.dance();
    }
}
